package com.example.crawler.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * org.hebeigaokao.common.utils
 *
 * @author 白雨浓
 * date: 17-7-26 下午3:23
 * content:业务id生成
 */
public class BusinessIDFactory {
    private static Random random = new Random();

    public synchronized static String getId() {
        SimpleDateFormat format = new SimpleDateFormat("yyMMddHHmmSSS");
        String data = format.format(new Date());
        format = null;
        return data + getRandom1() + getRandom2();
    }

    public synchronized static String getTimeStamp() {
        return timeStamp();
    }


    private static int getRandom1() {
        int r = random.nextInt(100000);

        while (r < 10000)
            r = random.nextInt(100000);

        return r;
    }

    private static int getRandom2() {
        int r = random.nextInt(10000);

        while (r < 1000)
            r = random.nextInt(10000);

        return r;
    }

    private static String timeStamp() {
        Date date = new Date();
        return String.valueOf((date.getTime()));
    }
}
